<?php
/**
 * Created by PhpStorm.
 * User: CuiLiwu
 * Date: 2018/4/17
 * Time: 14:37
 */

namespace App\Http\Controllers\Web\Member\Seller;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;


class ReceiveController extends BaseController
{
    protected $api_url = [
        'index' => ['get', 'seller/orders'],
        'show'  => ['get', 'seller/orders/%d'],
        'store' => ['post', 'seller/orders'],
        'update' => ['put', 'seller/orders/%d'],
        'delete' => ['delete', ''],
        'index_express_company' => ['get', 'seller/express_company']
    ];

    protected $api_host;

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->api_host = config('url.api_web');
    }

    public function index()
    {
        // ini_set('max_execution_time', '0');
        //参数部分
        $search_params = $this->request->all(['receivable_type', 'created_at']);
//        dd($search_params);
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'page' => $page,
            'with' => 'orderProducts;shop',
            'orderBy'=>'id',
            'sortedBy'=>'desc',
        ];

        //请求部分
        $ret = http_web($this->api_url['index'])->send($params);

        //结果处理部分
        $data = paginate($this->request, $ret['data']);

        //请求部分-快递公司
        $express_company = http_web($this->api_url['index_express_company'])->send(['type' => 'kv']);
        $data['express_company'] = $express_company['data'];

        //回填搜索框值
        $data['search_params'] = $search_params;
//        dd($data);
        return view('web.user.seller.receivables_list', $data);
    }
    public function show($id)
    {
        //参数部分
        $params = [
            'with' => 'shop;orderProducts;invoice;user;orderExpress'
        ];

        //请求部分
        $ret = http_web($this->api_url['show'], [$id])->send($params);

        //请求部分-快递公司
        $express_company = http_web($this->api_url['index_express_company'])->send(['type' => 'kv']);

        return view('web.user.seller.order_details', ['order' => $ret['data'], 'express_company' => $express_company['data']]);
    }
}